
layui.use([ 'layer', 'table', 'form'], function() {
    var layer = layui.layer //弹层
        ,table = layui.table //表格
        form = layui.form
            ,processId=getQueryVariable("processId")
            ,busskey=getQueryVariable("busskey")
            ,formkey=getQueryVariable("formkey")
            ,taskId=getQueryVariable("taskId")
        ;

    $("#lct")[0].src="process/traceprocess?processId="+processId;
    let param=formkey.lastIndexOf('costCode');
    if (param>-1){
        let costCode;
        $.ajax({
            type:"POST",
            dataType:"json",
            contentType: 'application/json',
            data:JSON.stringify(busskey),
            async:false,
            url:"cost/findCostById",
            success:function(res) {
                if(res.status == 200) {
                    costCode = res.data.code;
                }
            }
        });
        $("#lcyw")[0].src=formkey+"="+costCode;
    }else {
        $("#lcyw")[0].src=formkey+"="+busskey;
    }


    table.render({
        elem: '#approval'
        ,where:{"taskId":taskId}
        ,typ:"get"
        ,url:"process/getProcessComments"
        ,cols: [[
            //{field:'suppliertype', title:'审批历史记录'}
            {field:'message', title:'审批意见'}
            ,{field:'userId', title:'审批人员'}
           // ,{field:'suppliersource', title:'操作日期'}
            //,{field:'businesstypes', title:'申请人'}
        ]]
        ,id: 'approvalid'
        ,height: $(document).height() - $('#approval').offset().top - 150
        ,page: true
    });
});
function spyj(type) {
    var approvalopinion = $("#approvalopinion").val();
    if(type == "1"){
       // layer.msg("审核通过")
        commit(approvalopinion,type);
    }else if(type == "2"){
        bh(approvalopinion);
       // layer.msg("驳回");
    }else if(type == "0"){
        commit(approvalopinion,type);
    }
}
function commit(comment,type) {
   // var comment=$("#spyj").val();
    var obj={};
    obj.type=type;
    $.ajax({
        type : 'get'

        ,data:{"taskId":taskId,"variables":obj,"activityId":null,"comment":comment},
        url:'process/commitProcess',
        dataType:"json",
        /*  contentType: 'application/json',*/
        async:false,
        success : function (da) {
            if(da.status==200 ){
                layer.msg("提交成功");
                close();
                //parent.detab("views/jsp/SystemCenter/spdb.jsp");
                //parent.detab("views/jsp/SystemCenter/spdb.jsp","待办");
                //parent.intab("views/jsp/SystemCenter/sp.jsp")
                //parent.detab("views/jsp/SystemCenter/sp.jsp?processId="+processId+"&busskey="+busskey+"&formkey="+formkey+"&taskId="+taskId,"流程处理");
            }else{
                layer.msg("提交失败!");
            }
        },
        error: function(data) {
            // layer.msg("获取失败!");
        }
    });

}
function  bh(comment) {
   // var comment=$("#spyj").val();
    $.ajax({
        type : 'get'
        //  url : 'resource/getTree',
        //String taskId, Map<String, Object> variables, String activityId,String comment
        ,data:{"taskId":taskId,"variables":null,"comment":comment},
        url:'process/backProcess',
        dataType:"json",
        /*  contentType: 'application/json',*/
        async:false,
        success : function (da) {
            if(da.status==200 ){
                if(da.data==false){
                    layer.msg("当前节点不能驳回！");
                }else{
                    layer.msg("驳回成功");
                    close();
                }

            }else{
                layer.msg("驳回失败！");
            }
        },
        error: function(data) {
            // layer.msg("获取失败!");
        }
    });
}
function close() {
    var processKey=window.sessionStorage.processKey;
    parent.detab("views/jsp/SystemCenter/tpl/todo.jsp?processKey="+processKey,"待办事项")
    parent.intab("views/jsp/SystemCenter/tpl/todo.jsp?processKey="+processKey,"待办事项")
    //parent.detab("views/jsp/SystemCenter/tpl/approvalprocess.jsp?processId="+processId+"&busskey="+busskey+"&formkey="+formkey+"&taskId="+taskId,"审批流程处理")
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);//关闭当前页 
}